def binary_search(arr, target):
    """
    二分查询函数
    :param arr:
    :param target:
    :return:
    """
    n = len(arr)
    low = 0
    high = n - 1
    while low <= high:
        mid = (low + high) // 2
        if arr[mid] == target:
            print(f"index:{mid}, value:{arr[mid]}")
            return True
        # 左半边
        elif target < arr[mid]:
            high = mid - 1
        # 右半边
        else:
            low = mid + 1
    return False

if __name__ == '__main__':
    print("二分查找函数结果： ")
    list = [1, 3, 4, 5, 6, 7, 8]
    print(binary_search(list, 1))
